package com.imc.platform.base.teachsystem.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.imc.core.utils.MenuUtils;
import com.imc.platform.base.category.pojo.Category;
import com.imc.platform.base.notice.pojo.NoticeAttach;
import com.imc.platform.base.notice.service.INoticeService;
import com.imc.platform.base.teachsystem.service.ITeachSystemService;
import com.imc.platform.base.notice.pojo.Notice;
import com.twp.common.tuple.ResultDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * 类描述: 舞苑简介管理controller
 * 开发者:SJC
 * 创建时间:2018-8-17 16:37:33
 */
@Slf4j
@Controller
public class TeachSystemController {

    @Autowired
    ITeachSystemService iTeachSystemService;

    @Autowired
    MenuUtils menuUtils;

    @Autowired
    INoticeService iNoticeService;


    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    public static class ReqTuple{
        List<String> memberList;
        String noticeId;
        String contentDetail;
        String title;
        String type;
        String authorId;
    }

    @RequestMapping("/index/teachSystem")
    public String teachSystem(String menuId,Model model,HttpServletRequest request){
        model.addAttribute("menu", menuUtils.getMenuByRoleId(request,menuId));
        return "base/teachsystem/teachSystem";
    }

    /**
     * 方法描述:舞苑简介查询
     * SJC 2018-8-22 10:24:41
     */
    @RequestMapping("/index/queryTeachSystem")
    @ResponseBody
    public ResultDTO queryTeachSystem(Pageable pageable) throws Exception {
        PageInfo<Notice> noticeList = iTeachSystemService.queryTeachSystem(pageable.getPageNumber(), pageable.getPageSize());
        for(Notice c : noticeList.getList()){
            c.setPageNumber(pageable.getPageNumber());
            c.setPageSize(pageable.getPageSize());
        }
        JSONObject map = new JSONObject();
        map.put("total", noticeList.getTotal());
        map.put("rows", noticeList.getList());
        ResultDTO obj = ResultDTO.builder().data(map).build();
        return obj;
    }

    /**
     * 方法描述:详情查询 跳到编辑
     * SJC 2018-8-27 16:14:31
     */
    @GetMapping("/index/toUpdateTeachSystemTiny")
    public String toUpdateTeachSystemTiny(Model model,HttpServletRequest request){
        String ntId = "3";
        model.addAttribute("menu", menuUtils.getMenuByRoleId(request,"72"));
        Notice nt = iNoticeService.queryNoticeById(ntId);
        if(!"".equals(nt.getContent())){
            nt.setContent(nt.getContent());
        }
        nt.setSendIdList(iNoticeService.querySendMember(ntId,nt.getAuthorId()));
        model.addAttribute("notice", nt);
        List<NoticeAttach> naList = iNoticeService.queryNoticeAttachList(ntId);
        model.addAttribute("naList", naList);

        List<Category> categoryList = iNoticeService.queryCategory();
        model.addAttribute("categoryList",categoryList);

        model.addAttribute("type", "2");

        return "base/teachsystem/updateTeachSystemTinymce";

    }
}